$(document).ready(function () {
    dropdownOpen();//调用
});
/**
 * 鼠标划过就展开子菜单，免得需要点击才能展开
 */
function dropdownOpen() {

    var $dropdownLi = $('li.dropdown');

    $dropdownLi.mouseover(function () {
        $(this).addClass('open');
    }).mouseout(function () {
        $(this).removeClass('open');
    });
}

// 模糊查询
function selectAll() {
    //获取文本的内容
    var title = document.getElementById("searchName").value

    //发送到后台
    window.location = '/demand/selectAll?title=' + title

}

// 根据类别查询
function selectByCategory(id) {
    var categoryId = id;
    window.location = '/demand/selectByCategory?category_id=' + categoryId
}

// 根据详细类别查询
function selectByCategoryDetail(id) {
    var categoryDetailId = id;
    window.location = '/demand/selectByCategoryDetail?categorydetail_id=' + categoryDetailId
}

// 根据价格区间查询
function demandByPriceRange() {
    var minPrice = document.getElementById("minPrice").value;
    if (minPrice =="" ||undefined || null) {
        minPrice = 0
    }
    var maxPrice = document.getElementById("maxPrice").value;
    if(maxPrice == "" ||undefined || null){
        maxPrice = 0
    }
    window.location = '/demand/demandByPriceRange?minPrice='+ minPrice +"&maxPrice=" + maxPrice;
}


function serviceDetail(id) {
    var demandId = id;
    //alert(demandId);
    $.ajax({
        //提交数据的类型 POST GET
        type: "GET",
        //提交的网址
        url: "/demand/demandDetail",
        //提交的数据
        data: {id: demandId},
        dataType: 'json',
        //参数格式为json
        // contentType: "application/json; charset=utf-8",
        //返回数据的格式
        // datatype: "json",//"xml", "html", "script", "json", "jsonp", "text".
        //成功返回之后调用的函数
        success: function () {
            window.location = '/demand/demandDetailView'
        },
        //调用出错执行的函数
        error: function () {
            //请求出错处理
            alert("请求失败");
        }
    })
}